﻿using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Guids;
using Volo.Docs.Projects;

namespace Hd.Docs.VoloDocs
{
    public class VoloDocsDataSeeder : IVoloDocsDataSeeder, ITransientDependency
    {
        public IGuidGenerator GuidGenerator { get; set; }
        private VoloDocDataSeedOptions _options;
        private readonly IProjectRepository _projectRepository;
        public VoloDocsDataSeeder(
            IOptions<VoloDocDataSeedOptions> options,
            IProjectRepository projectRepository)
        {
            _options = options.Value;
            _projectRepository = projectRepository;
        }

        public async Task SeedAsync(Guid? tenantId = null)
        {
            try
            {
                await _projectRepository.GetByShortNameAsync(_options.ShortName);
            }
            catch (Exception)
            {

                var newDoc = new Project(
                         GuidGenerator.Create(),
                         _options.Name,
                         _options.ShortName,
                         "FileSystem",
                         _options.Format,
                         _options.DefaultDocumentName,
                         _options.NavigationDocumentName,
                         _options.ParametersDocumentName
                     );
                newDoc.ExtraProperties.Add("Path", _options.FilePath);
                await _projectRepository.InsertAsync(newDoc);
            }


        }
    }
}
